package com.ciwong.epaper.modules.msg.ui;

import android.annotation.TargetApi;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.support.v4.app.NotificationCompat;

import com.ciwong.epaper.R;


@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public class NotificationUtil {

    public static void sendCustomizedClockNotification(Context context, String notifyContent, String refId, String refType, long msgId) {

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                context);
        String notifyTitle = context.getResources().getString(R.string.app_name);
        //根据refType 跳转不同页面
//        if (null != refType) {
//        }
//        acceptIntent.putExtra(ClientConstants.JPUSH_KEY_REFID, refId);

        if (notifyContent == null || notifyContent.equals("")) {
            notifyContent = "亲，您收到一条新消息哦";
        }

        Intent intent = new Intent(context, MyMessageActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
        mBuilder.setContentIntent(pendingIntent);
        NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        mBuilder.setAutoCancel(true).
                setSmallIcon(R.mipmap.ic_launcher).setContentTitle(notifyTitle).setContentText(notifyContent).build();
        Notification notification = mBuilder.build();
        notification.sound = Uri.parse("content://settings/system/notification_sound");
        long[] vibrate = {0, 100, 200, 300};
        notification.vibrate = vibrate;
        // audioStreamType的值必须AudioManager中的值，代表着响铃的模式
        notification.audioStreamType = android.media.AudioManager.ADJUST_LOWER;
        notification.icon = R.mipmap.ic_launcher;
        notification.tickerText = notifyContent;
        //点击后自动消失
        notification.flags = Notification.FLAG_AUTO_CANCEL;
        //notification.cont
        // mId allows you to update the notification later on.
        //msgid 必须每个不同，要不然只会显示一个
        mNotificationManager.notify((int) msgId, notification);
    }


    public static void cleanNotification(int i, Context context) {
        NotificationManager manager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        manager.cancel(i);
    }

}
